package com.daniel.create.simfactory;

/**
 * @Description 简单工厂---简单工厂不是设计模式，更像是一种编程习惯。它把实例化的操作单独放到一个类中，这个类就成为简单工厂类，让简单工厂类来决定应该用哪个具体子类来实例化。
 * @Author GanShaoXi
 * @ClassName SimpleFactory
 * @Return com.daniel.create.simfactory
 * @Since 1.0.0
 * @Created on 2023/5/17 17:39
 */
public class SimpleFactory {
    public Project buildProject(ProjectEnum type) {
        if ("math".equals(type.name())) {
            return new MathProject();
        } else if ("biology".equals(type.name())) {
            return new BiologyProject();
        } else {
            return new ChemistryProject();
        }
    }

    /**
     * 测试
     *
     * @param args
     */
    public static void main(String[] args) {
        SimpleFactory simpleFactory = new SimpleFactory();
        Project project = simpleFactory.buildProject(ProjectEnum.BIOLOGY);
    }
}

interface Project {
}

/**
 * @Description 数学工程类
 * @Author GanShaoXi
 * @ClassName MathProject
 * @Return com.daniel.create.simfactory
 * @Since 1.0.0
 * @Created on 2023/5/17 19:32
 */
class MathProject implements Project {
}

/**
 * @Description 生物工程类
 * @Author GanShaoXi
 * @ClassName MathProject
 * @Return com.daniel.create.simfactory
 * @Since 1.0.0
 * @Created on 2023/5/17 19:32
 */
class BiologyProject implements Project {
}

/**
 * @Description 化学工程类
 * @Author GanShaoXi
 * @ClassName MathProject
 * @Return com.daniel.create.simfactory
 * @Since 1.0.0
 * @Created on 2023/5/17 19:32
 */
class ChemistryProject implements Project {
}

/**
 * @Description 工程类型枚举类
 * @Author GanShaoXi
 * @ClassName ProjectEnum
 * @Return com.daniel.create.simfactory.common
 * @Since 1.0.0
 * @Created on 2023/5/17 19:56
 */
enum ProjectEnum {
    /*数学工程*/
    MATH("math"),
    /*生物工程*/
    BIOLOGY("biology"),
    /*物理工程*/
    CHEMISTRY("chemistry");

    private String name;

    private ProjectEnum(String name) {
        this.name = name;
    }
}
